module RGB_Process
(
input 				clk_in, 
input             rst,
input 				rd_en, 
input [255:0]		rgb_in, 
input [7:0]			S_D_6_8,
output reg[23:0] 	rgb_out1,
output reg[23:0] 	rgb_out2

);
(* KEEP = "TRUE" *)reg[3:0] pixel_num;   
always @(posedge clk_in or posedge rst)
begin
	if (rst == 1'b1) begin
		rgb_out1 <= 24'h000000;
		rgb_out2 <= 24'h000000;
		pixel_num <= 4'd0;
	end
	else 
	begin 
		if(rd_en) begin
			if(S_D_6_8[3:0]>2) begin
				if(pixel_num==4'b0000) begin
					rgb_out1 <= rgb_in[39:16];
					rgb_out2 <= rgb_in[63:40];
					pixel_num <= 4'b0001;
				end
				else if(pixel_num==4'b0001) begin
					rgb_out1 <= rgb_in[87:64];
					rgb_out2 <= rgb_in[111:88];
					pixel_num <= 4'b0010;
				end
				else if(pixel_num==4'b0010) begin
					rgb_out1 <= rgb_in[135:112];
					rgb_out2 <= rgb_in[159:136];
					pixel_num <= 4'b0011;
				end
				else if(pixel_num==4'b0011) begin
					rgb_out1 <= rgb_in[183:160];
					rgb_out2 <= rgb_in[207:184];
					pixel_num <= 4'b0100;
				end
				else if(pixel_num==4'b0100) begin
					rgb_out1 <= rgb_in[231:208];
					rgb_out2 <= rgb_in[255:232];
					pixel_num <= 4'b0000;
				end
			end
			else begin		
				if(pixel_num==4'b0000) begin
					rgb_out1 <= rgb_in[39:16];
					rgb_out2 <= rgb_in[39:16];
					pixel_num <= 4'b0001;
				end
				else if(pixel_num==4'b0001) begin
					rgb_out1 <= rgb_in[63:40];
					rgb_out2 <= rgb_in[63:40];
					pixel_num <= 4'b0010;
				end
				else if(pixel_num==4'b0010) begin
					rgb_out1 <= rgb_in[87:64];
					rgb_out2 <= rgb_in[87:64];
					pixel_num <= 4'b0011;
				end
				else if(pixel_num==4'b0011) begin
					rgb_out1 <= rgb_in[111:88];
					rgb_out2 <= rgb_in[111:88];
					pixel_num <= 4'b0100;
				end
				else if(pixel_num==4'b0100) begin
					rgb_out1 <= rgb_in[135:112];
					rgb_out2 <= rgb_in[135:112];
					pixel_num <= 4'b0101;
				end
				else if(pixel_num==4'b0101) begin
					rgb_out1 <= rgb_in[159:136];
					rgb_out2 <= rgb_in[159:136];
					pixel_num <= 4'b0110;
				end
				else if(pixel_num==4'b0110) begin
					rgb_out1 <= rgb_in[183:160];
					rgb_out2 <= rgb_in[183:160];
					pixel_num <= 4'b0111;
				end
				else if(pixel_num==4'b0111) begin
					rgb_out1 <= rgb_in[207:184];
					rgb_out2 <= rgb_in[207:184];
					pixel_num <= 4'b1000;
				end
				else if(pixel_num==4'b1000) begin
					rgb_out1 <= rgb_in[231:208];
					rgb_out2 <= rgb_in[231:208];
					pixel_num <= 4'b1001;
				end
				else if(pixel_num==4'b1001) begin
					rgb_out1 <= rgb_in[255:232];
					rgb_out2 <= rgb_in[255:232];
					pixel_num <= 4'b0000;
				end
			end
		end
	end
end
   
endmodule

